import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
// 全局样式
import './assets/css/global.css'
//图标样式
import './assets/font/iconfont.css'
import './assets/font1/iconfont.css'
//导入axios
import axios from 'axios'
//挂载axios
Vue.prototype.$http=axios

Vue.config.productionTip = false

//访问后端根路径
axios.defaults.baseURL="http://localhost:8081"
//to是要去的页面，from是要离开的，next是个函数，否则就展示哪个页面
router.beforeEach((to,from,next)=>{
  const token =window.sessionStorage.getItem("user");
  if(token==null||token.length<=0){
    //没有登录
    if(to.path=="/login" || to.path=="/"){
      next();
    }else{
      alert("请先登录!");
      next("./login");
    }
  }else{
    //登录
    next();
  }
  
})
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
